﻿Option Strict On
Option Explicit On
Option Infer On

Imports System
Imports System.Linq
Imports System.Collections.Generic
Imports GenDotNet.TemplateSupport.StandardAttributeExtensions
Imports GenDotNet.Task.Common
Imports GenDotNet.TemplateSupport.Strings

Public Class ParameterInfo

   Private mName As String
   Private mParameterType As ParameterType
   Private mNetType As NetTypeInfo

   Public Sub New()
      Me.mParameterType = TemplateSupport.ParameterType.Value
   End Sub

   Public Sub New(ByVal name As String, ByVal nettype As NetTypeInfo)
      Me.New()
      Me.mName = name
      Me.mNetType = nettype
   End Sub

   Public Property Name() As String
      Get
         Return mName
      End Get
      Set(ByVal value As String)
         mName = value
      End Set
   End Property

   Public Property NetType() As NetTypeInfo
      Get
         Return mNetType
      End Get
      Set(ByVal value As NetTypeInfo)
         mNetType = value
      End Set
   End Property

   Public Property ParameterType() As ParameterType
      Get
         Return mParameterType
      End Get
      Set(ByVal value As ParameterType)
         mParameterType = value
      End Set
   End Property

End Class

Public Class ParameterInfoCollection
   Inherits List(Of ParameterInfo)

   Public Sub New(ByVal list As IEnumerable(Of ParameterInfo))
      MyBase.New(list)
   End Sub

   Public Sub New()
      MyBase.New()
   End Sub

   Public Overloads Sub Add(ByVal name As String, ByVal type As NetTypeInfo)
      Me.Add(New ParameterInfo(name, type))
   End Sub
End Class

Namespace VB
   Public Module ParameterInfoExtensions

      <System.Runtime.CompilerServices.Extension()> _
      Public Function Output(ByVal info As ParameterInfo) As String
         Return info.ParameterType.Output & " " & info.Name & " As " & info.NetType.Output
      End Function

      <System.Runtime.CompilerServices.Extension()> _
      Public Function Output(ByVal list As ParameterInfoCollection) As String
         If list Is Nothing OrElse list.Count = 0 Then
            Return String.Empty
         End If
         Dim last = list.Last
         Dim ret = String.Empty
         For Each item In list
            ret &= item.Output & If(item IsNot last, ", ", String.Empty)
         Next
         Return ret
      End Function

      <System.Runtime.CompilerServices.Extension()> _
      Public Function OutputForCall(ByVal info As ParameterInfo) As String
         Return info.Name
      End Function

      <System.Runtime.CompilerServices.Extension()> _
      Public Function OutputForCall(ByVal list As ParameterInfoCollection) As String
         If list Is Nothing OrElse list.Count = 0 Then
            Return String.Empty
         End If
         Return (From item In list Select (item.OutputForCall)).ConcatenateWithComma
      End Function

   End Module

End Namespace


Namespace CSharp
   Public Module ParameterInfoExtensions

      <System.Runtime.CompilerServices.Extension()> _
      Public Function Output(ByVal info As ParameterInfo) As String
         Return info.ParameterType.Output & " " & info.NetType.Output & " " & info.Name
      End Function

      <System.Runtime.CompilerServices.Extension()> _
      Public Function Output(ByVal list As ParameterInfoCollection) As String
         If list Is Nothing OrElse list.Count = 0 Then
            Return String.Empty
         End If
         Dim last = list.Last
         Dim ret = String.Empty
         For Each item In list
            ret &= item.Output & If(item IsNot last, ", ", String.Empty)
         Next
         Return ret
      End Function

      <System.Runtime.CompilerServices.Extension()> _
      Public Function OutputForCall(ByVal info As ParameterInfo) As String
         Return info.Name
      End Function

      <System.Runtime.CompilerServices.Extension()> _
      Public Function OutputForCall(ByVal list As ParameterInfoCollection) As String
         If list Is Nothing OrElse list.Count = 0 Then
            Return String.Empty
         End If
         Return (From item In list Select (item.OutputForCall)).ConcatenateWithComma
      End Function

   End Module

End Namespace
